<template>
  <view>
    <up-sticky bg-color="#fff" custom-nav-height="91">
      <Tabbar :tab-list="tabList" :right-action="true"
      @click="tabChange"/>
    </up-sticky>
    <up-gap height="50rpx" />
    <JobList :job-list="res"/>
  </view>
</template>

<script setup lang="ts">
import JobList from '@/pages/components/jobList/index.vue';
import Tabbar from '@/pages/components/tabbar/index.vue';
// import home06 from '@/static/images/tab/home-06.png';
// import home10 from '@/static/images/tab/home-10.png';
import { userJobType } from '@/api/user';
import { customerJobList } from '@/api/user/customer';
const home06 = "https://yiliao.test03.qcw800.com/static/images/tab/home-06.png";
const home10 = "https://yiliao.test03.qcw800.com/static/images/tab/home-10.png";

interface Tab {
  id: number;
  name: string;
  activeLineWidth: string;
}
const tabList = reactive<Tab[]>([
    // { name: '临床试验', activeLineWidth: '144' },
    // { name: '药剂师', activeLineWidth: '108' },
]);

onMounted(async () => {
  await nextTick(); // Ensure DOM is updated
  const query = uni.createSelectorQuery().in(this);
  query.select('.u-navbar').boundingClientRect((rect) => {
    console.log('Element height:', rect.height);
  }).exec();
});

const res:any = reactive([]);
async function getJobList(position_id : number = 0) {
  res.splice(0, res.length);
  let params:any = {
    status: 1
  }
  if (position_id > 0) {
    params['position_id'] = position_id
  }
  let r = await customerJobList(params, "找工作")
  if (!r) {
    uni.showToast({title: '获取职位列表失败', icon: 'none'})
    return
  }
  //赋值
   r.jobList.forEach(item => {
    res.push(item);
  })
}


const jobTitleList:any = reactive([])
async function getJobType() {
  let result = await userJobType();
  console.log('找工作职位类型::', result);
  for (let i = 0; i < result.length; i++) {
    const r = result[i]
    if (r.level == 2) {
      if (tabList.length < 2) {
        tabList.push({
          id: r.id,
          name: r.content,
          activeLineWidth: r.content.length == 3 ? '108' : '144'
        })
        console.log('插入分类 i:::', i)
      }
      jobTitleList.push({
        id: r.id,
        name: r.content
      })
    }
  }
  if (tabList.length > 0) {
    getJobList(tabList[0].id);
  }
}
const current_id = ref(0)
function tabChange(item) {
  if (current_id.value == 0) {
    current_id.value = 1
    if (tabList.length >= 2) {
      getJobList(tabList[1].id)
    }
  } else {
    current_id.value = 1
    if (tabList.length >= 1) {
      getJobList(tabList[0].id)
    }
  }
  console.log('找工作点击分类 item:::', item)

}

onLoad(() => {
  getJobType();
});
</script>

<style lang="scss" scoped>
  .tab-bar{
    height: 102rpx;
    background: #fff;
  }
</style>
